package org.totoro.structure.time;

import java.time.LocalDateTime;

/**
 * 周期类型
 *
 * @author daocr
 * @date 2020/4/7
 */
public enum CycleType {

    /**
     * 月
     */
    MONTH(12) {
        @Override
        public int format(LocalDateTime expiredTime) {
            return expiredTime.getMonthValue();
        }
    },
    /**
     * 日
     */
    DAY(31) {
        @Override
        public int format(LocalDateTime expiredTime) {
            return expiredTime.getDayOfMonth();
        }
    },
    /**
     * 小时
     */
    HOUR(24) {
        @Override
        public int format(LocalDateTime expiredTime) {
            return expiredTime.getHour();
        }
    },
    /**
     * 分钟
     */
    MINUTE(60) {
        @Override
        public int format(LocalDateTime expiredTime) {
            return expiredTime.getMinute();
        }
    },
    /**
     * 秒
     */
    SECOND(60) {
        @Override
        public int format(LocalDateTime expiredTime) {
            return expiredTime.getSecond();
        }
    };

    private int cycle;

    /**
     * 时间格式化
     *
     * @param expiredTime 过期时间
     * @return
     */
    public abstract int format(LocalDateTime expiredTime);

    public int getCycle() {
        return cycle;
    }

    CycleType(int cycle) {
        this.cycle = cycle;
    }
}
